/**
 * 
 */
package com.sokal.easycare.common.persistence;

import org.springframework.http.HttpStatus;

import com.sokal.easycare.common.message.PageMessage;

/**
 * 分页工具类
 * 
 * @author Administrator
 *
 * @param <T>
 */
public class PageUtil {

	public static PageMessage toPageMessage(Page page) {
		PageMessage ret = new PageMessage();

		ret.setPage(page.getPageNo());
		ret.setTotalPage(page.getTotalPage());
		ret.setStatus(HttpStatus.OK.value());
		ret.setItemsNum(page.getList().size());
		ret.setData(page.getList());
		ret.setResMsg("处理成功");
		ret.setPageNum(page.getPageSize());
		return ret;
	}

	public static PageMessage toDataMessage(Object object) {
		PageMessage ret = new PageMessage();

		ret.setPage(1);
		ret.setTotalPage(1);
		ret.setStatus(HttpStatus.OK.value());
		ret.setItemsNum(1);
		ret.setData(object);
		ret.setResMsg("处理成功");
		ret.setPageNum(1);
		return ret;
	}

	public static PageMessage toFailMessage(String msg) {
		PageMessage ret = new PageMessage();
		ret.setPage(1);
		ret.setTotalPage(1);
		ret.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
		ret.setItemsNum(1);
		ret.setResMsg(msg == null || msg == ""?"":msg);
		ret.setPageNum(1);
		return ret;
	}
}
